package com.chy.order_meal.controller;

import com.chy.order_meal.bean.ChyResponse;
import com.chy.order_meal.service.ResturantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/resturant/")
public class ResturantController {

    @Autowired
    ResturantService resturantService;

    @GetMapping("get/good")
    @ResponseBody
    public ChyResponse getGoodRestaurant(Integer page,Integer size){
        try {
            List data =resturantService.getPageByRecentOrderNum(page,size);
            return ChyResponse.simpSuccess(data);
        } catch (Exception e) {
            e.printStackTrace();
            return new ChyResponse(false,"查询错误",null);
        }
    }


    @GetMapping("get/all")
    @ResponseBody
    public ChyResponse getRestaurant(Integer page,Integer size){
        try {
            List data =resturantService.getRestaurant(page,size);
            return ChyResponse.simpSuccess(data);
        } catch (Exception e) {
            e.printStackTrace();
            return new ChyResponse(false,"查询错误",null);
        }
    }

    @GetMapping("/byType/get")
    @ResponseBody
    public ChyResponse getRestaurantByType(Integer type,Integer page,Integer size){
        try {
            List data =resturantService.getRestaurantByType(type,page,size);
            if(data == null){
                new ChyResponse(false,"该类型没有数据",null);
            }
            return ChyResponse.simpSuccess(data);
        } catch (Exception e) {
            e.printStackTrace();
            return new ChyResponse(false,"查询错误",null);
        }
    }



}
